import { GameData } from "../Data/GameData";
import UIManager from "../Manager/UIManager";

const { ccclass, property, executionOrder } = cc._decorator;

@ccclass
@executionOrder(103)
export default class GamePanel extends cc.Component {
    static Instance: GamePanel;

    @property(cc.Label)
    Label_level: cc.Label = null;

    @property(cc.Button)
    Button_back: cc.Button = null;
    @property(cc.Button)
    Button_setting: cc.Button = null;

    GeneratePoint_blook_list = [];

    onLoad() {
        GamePanel.Instance = this;

        this.GeneratePoint_blook_list = UIManager.Instance.GeneratePoint_blook.children;
    }

    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }

    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }

    Refresh() {
        this.Refresh_level();
    }

    Refresh_level() {
        this.Label_level.string = `Level ${GameData.CurrentLevel + 1}`;
    }

    AddListener() {
        this.Button_back.node.on("click", this.On_Button_back, this);
        // this.Button_setting.node.on("click", this.On_Button_setting, this);
    }

    RemoveListener() {
        this.Button_back.node.off("click", this.On_Button_back, this);
        // this.Button_setting.node.off("click", this.On_Button_setting, this);
    }

    On_Button_back() {
        this.ShowOff();
        cc.director.loadScene("MainScene");
    }

    // On_Button_setting() {
    //     // this.ShowOff();
    //     cc.director.loadScene("MainScene");
    // }
}

/** 调试 */
window["GamePanel"] = GamePanel;